<template>
  <div class="review-table-wrapper">
    <el-table :data="data" border style="width: 100%" align="center">
      <el-table-column prop="title" label="标题" fixed width="250"></el-table-column>
      <el-table-column prop="id" label="ID"></el-table-column>
      <el-table-column prop="author" label="作者" width="200"></el-table-column>
      <el-table-column prop="content" label="内容" width="200">
        <template slot-scope="scope">
          <p class="content">{{ scope.row.content }}</p>
        </template>
      </el-table-column>
      <el-table-column prop="useful_count" label="点赞数" width="100">
      </el-table-column>
      <el-table-column prop="created_at" label="发布日期" width="100">
        <template slot-scope="scope">
          <span>{{ formatDate(scope.row.created_at) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="rating" label="评分" width="100">
        <template slot-scope="scope">
          <span>{{ Number(scope.row.rating).toFixed(1) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="subject_id" label="电影ID" width="100"></el-table-column>
      <el-table-column prop="source" label="来源" width="120"></el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button
              @click="handleReviewDelete(scope.row.id, scope.row.title)"
              type="text"
              size="medium"
          >删除
          </el-button>
          <el-button @click="handleReviewUpdate(scope.row)" type="text" size="medium">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  import { formatDate } from "@/utils/util";

  export default {
    name: "ReviewTable",
    props: {
      data: {
        type: Array,
        default: []
      }
    },
    data() {
      return {};
    },
    methods: {
      handleReviewDelete(id, title) {
        this.$emit("delete", { id, title });
      },
      handleReviewUpdate(data) {
        this.$emit("update", data);
      },
      formatDate(date) {
        return formatDate(date)
      }
    }
  };
</script>

<style lang="scss" scoped>
  .review-table-wrapper {
    .content {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
</style>